using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Fieldbook.Entities;
using Fieldbook.Business;

namespace Fieldbook.Testwebsite
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string userName = txtUserName.Text;
            string password = txtPassword.Text;

            Appuser user = AppUserController.LoginUser(userName, password);
            if (user != null)
            {
                string role = user.Roleid.ToString();
                if (!Roles.RoleExists(role))
                {
                    Roles.CreateRole(role);
                }
                if (!Roles.IsUserInRole(userName, role))
                {
                    Roles.AddUserToRole(userName, role);
                }
                Session["userID"] = user.Userid;
                FormsAuthentication.RedirectFromLoginPage(userName, false);
            }
        }

    }
}
